import axios from 'axios';
import {Message} from 'element-ui';

//创建一个拦截器的instance(实例)
const instance=axios.create({
    baseURL:'http://macio.ncyateng.com',
    timeout:5000
})

//请求
instance.interceptors.request.use(
    (config)=>{
        // console.log(config);
        return config;  //一定要return 否则会出问题
    },
    (error)=>{
        return Promise.reject(error);
    }
);

//响应
instance.interceptors.response.use(
    (response)=>{
        // console.log(response);
        let {data:{code}}=response;
        if(code==0){
            return response;
        }else if(code==1){
            Message({
                message:'系统繁忙',
                type:'warning'
            })
        }
    },
    (error)=>{
        Message({
            message:'系统繁忙',
            type:'error'
        });
        return Promise.reject(error);   
    }
);

export default instance;